package eiisan.dao.domain.user;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.lang.Nullable;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 用户权限表
 * @table tb_permission
 * @date 2019-03-15
 */
@Setter
@Getter
@Entity
@Table(name = "tb_permission")
@ApiModel(description = "用户权限数据")
public class Permission implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 用户权限ID(不能为空)
	 */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "id")
	@ApiModelProperty(value = "用户权限ID")
	private Long id;

	/**
	 * 创建时间(不能为空)
	 */
	@Column(name = "create_time")
	@ApiModelProperty(value = "创建时间")
	private Date createTime;

	/**
	 * 类型 0:ALL 1:GET 2:POST 3:DELETE 4:PUT(不能为空,默认值:0)
	 */
	@Column(name = "type")
	@ApiModelProperty(value = "类型  0:ALL  1:GET  2:POST  3:DELETE  4:PUT", example = "0")
	private Byte type = 0;

	/**
	 * 权限名称(不能为空)
	 */
	@Column(name = "name", length = 100)
	@ApiModelProperty(value = "权限名称")
	private String name;

	/**
	 * 地址(不能为空)
	 */
	@Column(name = "url", length = 255)
	@ApiModelProperty(value = "地址")
	private String url;

	/**
	 * 描述
	 */
	@Nullable
	@Column(name = "description", length = 1000)
	@ApiModelProperty(value = "描述")
	private String description;

	/**
	 * 角色数据集合
	 */
	@ManyToMany
	@JoinTable(name="tb_role_permission",//中间表的名称
			//中间表tb_role_permission字段关联tb_permission表的主键字段id
			joinColumns={@JoinColumn(name="permission_id",referencedColumnName="id")},
			//中间表tb_role_permission的字段关联tb_role表的主键id
			inverseJoinColumns = {@JoinColumn(name="role_id",referencedColumnName="id")})
	@OrderBy("id asc")
	private Set<Role> roles = new HashSet<Role>(0);
}
